// 函数组件
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
import "./Audit.less"
import type { RadioChangeEvent } from 'antd';
import { Input, Radio, Space,message } from 'antd';
import { updateStatus } from "../../../../../api/lys"
function Audit(props: any) {
    const [messageApi, contextHolder] = message.useMessage();
    useEffect(() => {
        console.log('函数组件来咯')
    }, [])

    const {page,pageSize,goodsList,selectedRow,checkAudit1}=props
    const [value, setValue] = useState(1);

    //审核
    const updateStatu = async (obj:number[]) => {
        let res = await updateStatus({
            "ids":obj,
            "status":String(value) ,
        })
        if(res.code=="200"){
            console.log("审核成功");
            await goodsList(page,pageSize)
            
            messageApi.open({
                type: 'success',
                content: '审核成功',
              });
              props.isAudit(false);
        }
    }


    const onChange = (e: RadioChangeEvent) => {
        console.log('radio checked', e.target.value);
        setValue(e.target.value);
    };
    const okAudit = () => {
        if (props.auditType == "审核") {
            let arrs:number[] = []
            arrs.push(checkAudit1.goodsId)
            console.log("表单单项审核执行了");
            updateStatu(arrs)
        }
        if (props.auditType == "批量审核") {
            console.log("批量审核执行了")
            updateStatu(selectedRow)

        }
    }

    return (
        <div className='Audit'>
            {contextHolder}
            <div>
                <h2>商品审核</h2>
            </div>
            <div>
                <div>
                    <p>审核意见</p>
                </div>
                <div>
                    <Radio.Group onChange={onChange} value={value}>
                        <Space direction="vertical">
                            <Radio value={0}>待审核</Radio>
                            <Radio value={1}>已审核</Radio>
                            <Radio value={2}>未通过</Radio>
                        </Space>
                    </Radio.Group>
                </div>
            </div>
            <div>
                <button onClick={okAudit}>确定</button>
                <button onClick={() => { props.isAudit(false) }}>取消</button>
            </div>
        </div>
    )
}

export default Audit